﻿using IterationLife.Domains.Sports.Models;
using Util;
using Util.Maps;

namespace IterationLife.Football.MTSports.Dtos.Sports {
    /// <summary>
    /// 体育队伍数据传输对象扩展
    /// </summary>
    public static class SportTeamDtoExtension {
        /// <summary>
        /// 转换为体育队伍实体
        /// </summary>
        /// <param name="dto">体育队伍数据传输对象</param>
        public static SportTeam ToEntity( this SportTeamDto dto ) {
            if ( dto == null )
                return new SportTeam();
            return dto.MapTo( new SportTeam( dto.Id.ToGuid() ) );
        }
        
        /// <summary>
        /// 转换为体育队伍实体
        /// </summary>
        /// <param name="dto">体育队伍数据传输对象</param>
        public static SportTeam ToEntity2( this SportTeamDto dto ) {
            if( dto == null )
                return new SportTeam();
            return new SportTeam( dto.Id.ToGuid() ) {
                PartnerTeamId = dto.PartnerTeamId,
                Name = dto.Name,
                Logo = dto.Logo,
                PersonCount = dto.PersonCount,
                HistoryAverageJsonData = dto.HistoryAverageJsonData,
                CreationTime = dto.CreationTime,
                CreatorId = dto.CreatorId,
                LastModificationTime = dto.LastModificationTime,
                LastModifierId = dto.LastModifierId,
                IsDeleted = dto.IsDeleted,
                Version = dto.Version,
            };
        }
        
        /// <summary>
        /// 转换为体育队伍数据传输对象
        /// </summary>
        /// <param name="entity">体育队伍实体</param>
        public static SportTeamDto ToDto(this SportTeam entity) {
            if( entity == null )
                return new SportTeamDto();
            return entity.MapTo(new SportTeamDto());
        }

        /// <summary>
        /// 转换为体育队伍数据传输对象
        /// </summary>
        /// <param name="entity">体育队伍实体</param>
        public static SportTeamDto ToDto2( this SportTeam entity ) {
            if( entity == null )
                return new SportTeamDto();
            return new SportTeamDto {
                Id = entity.Id.ToString(),
                PartnerTeamId = entity.PartnerTeamId,
                Name = entity.Name,
                Logo = entity.Logo,
                PersonCount = entity.PersonCount,
                HistoryAverageJsonData = entity.HistoryAverageJsonData,
                CreationTime = entity.CreationTime,
                CreatorId = entity.CreatorId,
                LastModificationTime = entity.LastModificationTime,
                LastModifierId = entity.LastModifierId,
                IsDeleted = entity.IsDeleted,
                Version = entity.Version,
            };
        }
    }
}
